<template>
    <div>
        <keep-alive>
            <router-view v-if="$route.meta.keepAlive"/>

        </keep-alive>
        <router-view  v-if="!$route.meta.keepAlive"/>

        <my-popup v-model="topShow" @change="changePopup" ref="login"></my-popup>
    </div>
</template>

<script>
    import wxValidate from '@/config/wx.validate'
    import {mapMutations,mapGetters} from 'vuex'
    import myPopup from "@/components/myPopup";
    export default {
        mixins: [wxValidate],
        components: {myPopup},
        computed: {...mapGetters(['showLogin','wxInfo'])},
        data() {
            return {
                topShow: false
            }
        },

        watch:{
            showLogin(val){
                if(val){
                    this.topShow = val;
                }

            }
        },
        created(){

            // let user = {
            //     id: "1301174891015221249",
            //     nickname: "Toby",
            //     phone: "18080476203",
            //     sex: 1,
            //     headImageUrl: "http://thirdwx.qlogo.cn/mmopen/pfh9gxSGcRiaKDzUOfLBmUwSgBKUAko9XnabvqmeKiczLE3XGy8mib0JNQMawGBoIr8mBnqRoxS2wjAosFk1Gt2zhg7KQqzVTxy/132",
            //     province: "四川",
            //     city: "南充",
            //     status: 1,
            //     wxOpenId: "o8MiRwbxHYbjWiuUURCqIP0YBmog"
            // };
            // localStorage.setItem('wxInfo',JSON.stringify(user));
            if(!Object.keys(this.wxInfo).length){
                return this.$router.replace('/wx');
            }
            this.getUserInfo();
            this.getSystemInfo();
        },


        mounted(){

            // this.wxSignature();
        },
        methods: {
            ...mapMutations(['SET_LOGIN_STATUS','SET_USERINFO',"SET_SYSTEM"]),

            //获取系统信息
            async getSystemInfo(){
                const res = await this.$http.get('/common/mp/systemInfo');
                this.SET_SYSTEM(res.data);
            },


            //获取用户信息
            async getUserInfo(){

                const res = await this.$http.get('/mp/user/info');
                if(res.errorCode !== '00000'){

                }else {
                    localStorage.setItem('userinfo',JSON.stringify(res.data));
                    this.SET_USERINFO(res.data);
                }


            },

            changePopup(val){
                if(!val){
                    this.SET_LOGIN_STATUS(false);
                }
            }
        }

    }
</script>
